package com.dsteiner.xelavos.client;

import java.util.List;

import com.dsteiner.widgets.client.FileUploadWidget;
import com.dsteiner.widgets.client.Widgets.FlowPanelExt;
import com.dsteiner.widgets.client.Widgets.HTMLExt;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.model.FileUploadModel;
import com.dsteiner.widgets.client.resources.WidgetsResources;
import com.dsteiner.xelavos.client.controller.ChangeImageController;
import com.dsteiner.xelavos.client.controller.CreateObjectController.ImageSuggestions;
import com.dsteiner.xelavos.client.resources.XelavosResources;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;

public class ChangeImageWidget extends LazyWidget {

	public static class ChangeImageModel extends FileUploadModel{
		private List<ImageSuggestions> imageUrls;

		public List<ImageSuggestions> getImageUrls() {
			return imageUrls;
		}

		public void setImageUrls(List<ImageSuggestions> imageUrls) {
			List<ImageSuggestions> oldImageUrls = this.imageUrls;
			this.imageUrls = imageUrls;
			propertyChangeSupport.firePropertyChange("imageUrls", oldImageUrls, imageUrls);
		}
		private String selectedImageUrl;

		public String getSelectedImageUrl() {
			return selectedImageUrl;
		}

		public void setSelectedImageUrl(String selectedImageUrl) {
			String oldSelectedImageUrl = this.selectedImageUrl;
			this.selectedImageUrl = selectedImageUrl;
			propertyChangeSupport.firePropertyChange("selectedImageUrl", oldSelectedImageUrl, selectedImageUrl);
		}
	}

	private ChangeImageController changeImageController = new ChangeImageController();
	private final ChangeImageModel changeImageModel;

	public ChangeImageWidget(ChangeImageModel changeImageModel) {
		this.changeImageModel = changeImageModel;
		setStyleName(XelavosResources.INSTANCE.css().changeImageWidget());
	}

	@Override
	public Widget createContentWidget() {
		FlowPanel mainPanel = new FlowPanel();
		FileUploadWidget fileUploadWidget = new FileUploadWidget(changeImageModel);
		HTMLExt headerHtml = new HTMLExt("O haga click en uno de los siguientes imagenes");
		FlowPanelExt imagePanel = new FlowPanelExt();
		FlowPanelExt imageContentPanel = new FlowPanelExt();
		
		mainPanel.add(fileUploadWidget);
		mainPanel.add(imagePanel);
		imagePanel.add((Widget)headerHtml);
		imagePanel.add((Widget)imageContentPanel);
		
		headerHtml.addStyleName(WidgetsResources.INSTANCE.css().headerHtml());
		
		changeImageController.registerChangeImageWidget(this);
		changeImageController.registerChangeImageModel(changeImageModel);
		changeImageController.registerImagePanel(imagePanel);
		changeImageController.registerImageContentPanel(imageContentPanel);
		return mainPanel;
	}

}